</html>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tracker</title>
  <script>
    function $(id) {
      return document.getElementById(id);
    }
  </script>
  <style>
    body {
      background: #595959;
      margin: 0;
    }

    main {
      height: 100vh;
    }

    article.analysis {
      display: flex;
      background: #595959;
      padding: 20px;
      height: -webkit-fill-available;
    }

    button {
      background: dimgray;
      border: blue;
    }

    div.code {
      display: flex;
      flex-direction: column;
      width: 50%;
      margin-left: 10px;
      margin-right: 10px;
    }

    textarea {
      background: dimgray;
      height: -webkit-fill-available;
      border: none;
      border-radius: 10px;
      padding: 2em;
      font-weight: bold;
    }

    button {
      margin-top: 10px;
      border-radius: 10px;
      padding: 1em;
    }

    div.analysis {
      background: dimgray;
      border: none;
      border-radius: 10px;
      padding: 2em;
      font-weight: bold;
      width: 50%;
      margin-left: 10px;
      margin-right: 10px;
    }
  </style>
</head>

<body>
  <main>
    <article class="analysis">
      <div class="code">
        <textarea id="ta-code" style="color: gainsboro">
public class Code {
  public static void main() {
    System.out.println("Input your codes here!");
  }
}</textarea>
        <button id="submit" style="color: gainsboro">Submit</button>
        <button id="analyse" style="color: gainsboro">Analyse</button>
      </div>
      <div class="analysis" style="color: gainsboro">可视化区域</div>
    </article>
  </main>

  <script src="Intent.js"></script>
  <script>
    let code = $("ta-code").value;
    $("submit").addEventListener("click", () => {
      postCode("http://localhost:8080/analysis/codes", code, (responseText) => {
        alert("Submit");
        console.log(responseText);
      });
    });

    let events;
    $("analyse").addEventListener("click", () => {
      getAnalysis("http://localhost:8080/analysis/", 1, (responseText) => {
        alert("Analyse");
        events = JSON.parse(responseText);
        for (let event of events) {
          console.log(event.type);
        }
      });
    })
  </script>
</body>

</html>